package com.jspgou.cms.dao.impl;

import org.hibernate.Criteria;
import org.springframework.stereotype.Repository;
import com.jspgou.common.hibernate3.Finder;
import com.jspgou.common.hibernate3.HibernateBaseDao;
import com.jspgou.common.page.Pagination;
import com.jspgou.cms.dao.ShopSupplierDao;
import com.jspgou.cms.entity.ShopSupplier;

@Repository
public class ShopSupplierDaoImpl extends HibernateBaseDao<ShopSupplier, Long> implements ShopSupplierDao {
	public Pagination getPage(int pageNo, int pageSize) {
		Criteria crit = createCriteria();
		Pagination page = findByCriteria(crit, pageNo, pageSize);
		return page;
	}

	public ShopSupplier findById(Long id) {
		ShopSupplier entity = get(id);
		return entity;
	}

	public ShopSupplier save(ShopSupplier bean) {
		getSession().save(bean);
		return bean;
	}

	public ShopSupplier deleteById(Long id) {
		ShopSupplier entity = super.get(id);
		if (entity != null) {
			getSession().delete(entity);
		}
		return entity;
	}
	
	@Override
	protected Class<ShopSupplier> getEntityClass() {
		return ShopSupplier.class;
	}
	
	private Finder getFinderForTag(String merchantid) {
		String hql = "from ShopSupplier where merchantid='"+merchantid+"'";
		Finder f = Finder.create(hql);
		f.append(" order by id desc");
		f.setCacheable(true);
		return f;
	}

	public Pagination getPageByTag(String merchantid,int pageNo,int pageSize) {
		
		Finder f = getFinderForTag(merchantid);
		return find(f, pageNo, pageSize);
	}
}